﻿namespace EFS.Common.Async
{
	/// <summary>
	/// Async process wait list
	/// </summary>
	public class AsyncWaitList 
	{
		// Root
		System.Collections.Generic.List<AsyncProcess> list = new System.Collections.Generic.List<AsyncProcess>();

		/// <summary>
		/// Constructor
		/// </summary>
		public AsyncWaitList(AsyncProcess[] array = null)
		{
			// if any copy
			if (null != array)
			{
				list.AddRange(array);
			}
		}

		/// <summary>
		/// Wait all
		/// </summary>
		public void WaitAll()
		{
			// wait completed
			foreach (AsyncProcess asyncProcess in list)
			{
				asyncProcess.WaitComplete();
			}
		}

		/// <summary>
		/// Add
		/// </summary>
		/// <param name="asyncProcess"></param>
		public void Add(AsyncProcess asyncProcess)
		{
			// check
			EFS.Common.Verify.Reference(asyncProcess, "asyncProcess");

			// add to list
			list.Add(asyncProcess);
		}
	}

}